package com.thor.palmmall.rest.order.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.common.OperateInfoConverter;
import com.thor.palmmall.rest.order.AProduct;
import com.thor.palmmall.spi.order.SProduct;

public class AProductConverter implements Converter<SProduct, AProduct> {
  private static AProductConverter instance;

  public static AProductConverter getInstance() {
    if (instance == null)
      instance = new AProductConverter();
    return instance;
  }

  private AProductConverter() {
  }

  @Override
  public AProduct convert(SProduct source) {
    if (source == null) {
      return null;
    }
    AProduct target = new AProduct();
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setCreateInfo(OperateInfoConverter.getInstance().convert(source.getCreateInfo()));
    target
        .setLastModifyInfo(OperateInfoConverter.getInstance().convert(source.getLastModifyInfo()));
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setCode(source.getCode());
    target.setName(source.getName());
    target.setState(source.getState());
    target.setProductType(source.getProductType());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setTenant(UCN.newInstance(source.getTenant()));
    target.setContract(UCN.newInstance(source.getContract()));
    target.setPosition(UCN.newInstance(source.getPosition()));
    target.setContractPeriod(source.isContractPeriod());
    target.setBeginTime(source.getBeginTime());
    target.setEndTime(source.getEndTime());
    target.setRemark(source.getRemark());
    target.setTaxRates(source.getTaxRates());
    target.setPrice(source.getPrice());
    target.setBrand(AProductBrandConverter.getInstance().convert(source.getBrand()));
    target
        .setMainCategory(AProductCategoryConverter.getInstance().convert(source.getMainCategory()));
    target.setCategory(AProductCategoryConverter.getInstance().convert(source.getCategory()));
    target.setTaxRate(AProductTaxRateConverter.getInstance().convert(source.getTaxRate()));
    target.setOtherTaxRates(source.getOtherTaxRates());
    // target.setProperties(AProductPropertiesConverter.getInstance().convert(source.getProperties()));
    target.setProperties(source.getProperties());
    target.setFileIds(source.getFileIds());
    target.setInvoiceCategories(source.getInvoiceCategories());
    return target;
  }

}
